package com.googlecode.xapper

import static org.hamcrest.Matchers.*
import static org.junit.Assert.*

import org.junit.*

import nu.xom.*

public class TestElementWrapperSiblings{
	
	def context = new XPathContext("html", "http://www.w3.org/1999/xhtml");

	@Test
	public void shouldCreateASibilingNode() {
		def root = HtmlElementWrapper.create("div").asElement()
		def wrapper = HtmlElementWrapper.element(root)
		
		wrapper.withChild("div").withSibling("div")
		
		def nodes = root.query("//html:div/html:div", context)
		
		assertThat(nodes.size(), is(2))
	}

	@Test(expected=IllegalStateException.class)
	public void shouldThrowAnExceptionIfASibilingIsCreatedOnARoot() {
		def wrapper = HtmlElementWrapper.create("html")
		
		wrapper.withSibling("html")
	}
	
}
